#pragma once
#include"noncopyable.h"

#include<thread>
#include<functional>
#include<memory>
#include<string>
#include<atomic>
#include <unistd.h>
class Thread:noncopyable
{
    public:
        using ThreadFunc = std::function<void()>;//线程函数负责执行特定的任务
        explicit Thread(ThreadFunc,const std::string &name =std::string());
        ~Thread();

        void start();
        void join();
        bool started()const {return started_;}
        pid_t tid() const {return tid_;}

        const std::string& name() const {return name_;}
        static int numCreate() {return numCreated_;}
    private:
        void setDefaultName();
        bool started_;
        bool joined_;
        //std::thread thread_;//不能直接这么定义，这么定义之后直接就开启一个线程了，我们得自己掌控它的开启，所以用个智能指针
        std::shared_ptr<std::thread> thread_;
        pid_t tid_;
        ThreadFunc func_;
        std::string name_;//打印的时候加的调试信息
        static std::atomic_int numCreated_;//对所有线程进行计数的，所以是静态的ss
    };